package com.theme.common.third;

/**
 * 类名:QQController <tb>
 * 描述:微信登录接口  <tb>
 * 作者:cuixinfu@51play.com <tb>
 */

public class QQController {

//    @RestController
//    @RequestMapping("app/qq")
//    @Api("qq测试接口")
//
//    private static Logger logger = LoggerFactory.getLogger(QQController.class);
//
//    @Autowired
//    private JwtUtils jwtUtils;
//
//    @Autowired
//    private UserService userService;
//
//    @Autowired
//    private QQConfig qqConfig;
//
//    /**
//     * @描述: 获取PC网页扫码url地址
//     * @创建人: cuixinfu@51play.com
//     */
//    @RequestMapping("/scanQrcode")
//    public void scanQrcode (HttpServletRequest request, HttpServletResponse response) throws IOException {
//        String service = request.getParameter("service");
//        String defaultPage = request.getParameter("defaultPage");
//        String updateServer = request.getParameter("updateServer");
//        String c = "UTF-8";
//        String state= StringHandler.getRandomString(64);
//        String callbackUrl = qqConfig.getRedirectUri()+"?service="+ URLEncoder.encode(service, c)
//                +"&defaultPage="+ URLEncoder.encode(defaultPage, c)
//                +"&updateServer="+ updateServer;
//        StringBuilder sb = new StringBuilder();
//        sb.append("https://graph.qq.com/oauth2.0/authorize?display=pc&response_type=code&client_id=APPID&state=STATE");
//        sb.append("&redirect_uri=").append(URLEncoder.encode(callbackUrl,c));
//        String wxLoginUrl = response.encodeURL(sb.toString().replace("APPID", qqConfig.getAppId())).replace("STATE",state);
//        logger.info("微信PC网页扫码授权qrcode --> auth url = {}",wxLoginUrl);
//        response.sendRedirect(wxLoginUrl);
//    }
//
//    @GetMapping("callback")
//    @ApiOperation("QQ回调")
//    public void callback(HttpServletRequest request, HttpServletResponse response) throws Exception {
//        response.setCharacterEncoding("UTF-8");
//        response.setHeader("Content-type", "text/html;charset=UTF-8");
//
//        String state = request.getParameter("state");
//        String code = request.getParameter("code");
//        String defaultPage = request.getParameter("defaultPage");
//        String service = request.getParameter("service");
//        String updateServer = request.getParameter("updateServer");
//        if (StringHandler.isEmpty(code) || code == null){
//            logger.info("qq授权出错回调code参数 ===== auth code is null");
//            service = defaultPage+"?message="+ URLEncoder.encode("错误消息", "UTF-8");;
//            //service = defaultPage+"?message="+ URLEncoder.encode(PassportErrorCode.QQ_OAUTH_VERIFY_ERROR.getMessage(), "UTF-8");;
//            response.sendRedirect(service);
//            return;
//        }
//
//        String accessToken = QQHandler.getAccessTokenByCode(qqConfig.getAppId(),qqConfig.getAppKey(),qqConfig.getRedirectUri(),code);
//        Map<String, String> qqInfo = QQHandler.getUserInfoByAccessToken(qqConfig.getAppId(), accessToken);
//        if (StringHandler.isEmpty(qqInfo)){
//            logger.info("qq get user info ===== getUserInfo error");
//            service = defaultPage+"?message="+ URLEncoder.encode("错误消息", "UTF-8");
//            //service = defaultPage+"?message="+ URLEncoder.encode(PassportErrorCode.QQ_OAUTH_GET_USER_INFO_ERROR.getMessage(), "UTF-8");
//            response.sendRedirect(service);
//            return;
//        }
//        String qqUserjson = JSONHandler.getJsonStr(qqInfo);
//        logger.info("qqCallback return qqUserInfo ===={}",qqUserjson);
//        QQUserInfo qqUserInfo = JSONHandler.getObjectByJsonStr(qqUserjson, QQUserInfo.class);
//        return;
//    }

}
